package com.diyunapp.xilinapp.adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.diyunapp.xilinapp.R;
import com.diyunapp.xilinapp.bean.GoodsBuyRecordsBean;
import com.diyunapp.xilinapp.utils.FormatConfirm;
import com.diyunapp.xilinapp.utils.MyDateUtils;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by NIDAYE on 2016/6/21.
 */
public class GoodsBuyRecordsAdapter extends BaseAdapter {

    private List<GoodsBuyRecordsBean> myLists;
    private Context myContext;

    public GoodsBuyRecordsAdapter(List<GoodsBuyRecordsBean> myLists, Context myContext) {
        this.myLists = myLists;
        this.myContext = myContext;
    }

    @Override
    public int getCount() {
        return myLists.size();
    }

    @Override
    public Object getItem(int position) {
        return myLists.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(myContext).inflate(R.layout.buy_records_list, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }
        else
        {
            holder = (ViewHolder)convertView.getTag();
        }
        GoodsBuyRecordsBean data = myLists.get(position);
        holder.buyrecordsBuyeridTv.setText(FormatConfirm.usernameEncode(data.getBuyerId()));
        holder.buyrecordsBuypirceTv.setText("￥"+ data.getBuyPrice());
        holder.buyrecordsBuynumTv.setText(data.getBuyNumber());
        Long time = Long.parseLong(data.getBuyTime());
        holder.buyrecordsBuytimeTv.setText(MyDateUtils.getCompleteTime(time));

        return convertView;
    }

    static class ViewHolder {
        @Bind(R.id.buyrecords_buyerid_tv)
        TextView buyrecordsBuyeridTv;
        @Bind(R.id.buyrecords_buypirce_tv)
        TextView buyrecordsBuypirceTv;
        @Bind(R.id.buyrecords_buynum_tv)
        TextView buyrecordsBuynumTv;
        @Bind(R.id.buyrecords_buytime_tv)
        TextView buyrecordsBuytimeTv;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
